//
//  MessageEntity+CoreDataProperties.swift
//  JKTools
//
//  Created by 姜奎 on 2/20/25.
//
//

import Foundation
import CoreData

extension MessageEntity {

    @nonobjc public class func fetchRequest() -> NSFetchRequest<MessageEntity> {
        return NSFetchRequest<MessageEntity>(entityName: "MessageEntity")
    }

    @NSManaged public var messageId: String
    @NSManaged public var sessionId: String
    @NSManaged public var content: Data
    @NSManaged public var timestamp: Date
    @NSManaged public var sender: String

}

extension MessageEntity: Identifiable {
    public var id: NSManagedObjectID { objectID }
}

extension MessageEntity : JKCoreDataModelProtocol {
    public func insertNewSubObject(with entity: NSManagedObject) {
        
    }
    
    public static func insertNewObject<T>(with properties: T, into context: NSManagedObjectContext) -> NSManagedObject? {
        guard let properties = properties as? Message else { return nil }
        let group = NSEntityDescription.insertNewObject(forEntityName: "MessageEntity", into: context) as! MessageEntity
        group.messageId = properties.id
        group.sessionId = properties.sessionId
        group.content = properties.content
        group.timestamp = properties.timestamp
        group.sender = properties.sender.rawValue
        return group
    }
}

